home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / sbprolog / amiga / cmplibsr.zoo / $asmpass11.P < prev    next >
Text File  |  1988-09-15  |  7KB  |  213 lines

  1. /************************************************************************
  2. *                                    *
  3. * The SB-Prolog System                            *
  4. * Copyright SUNY at Stony Brook, 1986; University of Arizona,1987    *
  5. *                                    *
  6. ************************************************************************/
  7.  
  8. /*-----------------------------------------------------------------
  9. SB-Prolog is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY.  No author or distributor
  11. accepts responsibility to anyone for the consequences of using it
  12. or for whether it serves any particular purpose or works at all,
  13. unless he says so in writing.  Refer to the SB-Prolog General Public
  14. License for full details.
  15.  
  16. Everyone is granted permission to copy, modify and redistribute
  17. SB-Prolog, but only under the conditions described in the
  18. SB-Prolog General Public License.   A copy of this license is
  19. supposed to have been given to you along with SB-Prolog so you
  20. can know your rights and responsibilities.  It should be in a
  21. file named COPYING.  Among other things, the copyright notice
  22. and this notice must be preserved on all copies. 
  23. ------------------------------------------------------------------ */
  24. /* **********************************************************************
  25. $asmpass11_export([$asm_pass1/6]).
  26.  
  27. $asmpass11_use($blist,[_,_,$member1/2]).
  28. $asmpass11_use($name,[$name/2,_]).
  29. $asmpass11_use($meta,[_,_,$length/2]).
  30. $asmpass11_use($listutil1,[_,_,_,_,_,_,$member2/2,$closetail/1]).
  31. ********************************************************************** */
  32.  
  33. $asm_pass1(AsmInsts, Index, Csym, Lsym, Ntext, Npsc) :-
  34.     $asm_pass1(AsmInsts,Lsym,Csym,0,Ntext),
  35.     $asm_index_pass1(Index, Csym),
  36.     $asm_uniq( Lsym, EPtable ), 
  37.     $closetail( Lsym ),
  38.     $closetail( EPtable ),
  39.     $asmpass1_fillin( EPtable, Csym ),
  40.     $asmpass1_setundef( Csym, Npsc, 0),
  41.     !.
  42.  
  43. $asm_index_pass1([],_).
  44. $asm_index_pass1([pred(_,_)|Rest], Csym) :- $asm_index_pass1(Rest, Csym).
  45. $asm_index_pass1([arglabel(T,Val,Label)|Rest],Csym) :-
  46.     (T ?= c ->
  47.          $member1((Val, 0, _), Csym);
  48.          (T ?= s -> 
  49.              (Val = (Str, Ar), $member1((Str, Ar, _), Csym)) ;
  50.              true
  51.          )
  52.     ),
  53.     $asm_index_pass1(Rest, Csym).
  54.  
  55. $asm_pass1([],_,_,Lc,Lc).
  56. $asm_pass1([Inst| Rest], Lsym, Csym, Lc, NLc):-
  57.      (Inst \= label(_) ->
  58.          ($asm_pass1(Inst,Csym,N),
  59.           Lc0 is Lc + N
  60.      ) ;
  61.      (Inst = label(X),
  62.           $member1((X, Lc), Lsym),
  63.       Lc0 = Lc
  64.      )
  65.     ),
  66.     $asm_pass1(Rest, Lsym, Csym, Lc0, NLc).
  67.  
  68.         
  69. :- mode $asm_pass1(++,?,-).
  70.  
  71. $asm_pass1(label(X),_,0).
  72. $asm_pass1(getpvar(V,R),_,4).
  73. $asm_pass1(getpval(V,R),_,4).
  74. $asm_pass1(gettval(R,R1),_,4).
  75. $asm_pass1(getcon(C,R),Csym,6) :-
  76.      $member1((C,0,_), Csym).
  77. $asm_pass1(getnumcon(I,R),_,6).
  78. $asm_pass1(getfloatcon(I,R),_,6).
  79. $asm_pass1(getnil(R),_,2). 
  80. $asm_pass1(getstr((S,N),R),Csym,6) :-
  81.      $member1((S,N,_),Csym).
  82. $asm_pass1(getlist(R),_,2).
  83. $asm_pass1(getlist_k(R),_,2).
  84. $asm_pass1(getlist_tvar_tvar(R0,R1,R2),_,4).
  85. $asm_pass1(getlist_k_tvar_tvar(R0,R1,R2),_,4).
  86. $asm_pass1(getcomma(R),_,2).
  87. $asm_pass1(getcomma_tvar_tvar(R0,R1,R2),_,4).
  88. $asm_pass1(unipvar(V),_,2).
  89. $asm_pass1(unipval(V),_,2).
  90. $asm_pass1(unitvar(R),_,2).
  91. $asm_pass1(unitval(R),_,2).
  92. $asm_pass1(unicon(C),Csym,6) :-
  93.      $member1((C,0,_),Csym).
  94. $asm_pass1(uninumcon(N),_,6). 
  95. $asm_pass1(unifloatcon(N),_,6). 
  96. $asm_pass1(uninil,_,2).
  97. $asm_pass1(test_unifiable(R1,R2,R3),_,4).
  98. $asm_pass1(putpvar(V,R),_,4).
  99. $asm_pass1(putpval(V,R),_,4).
  100. $asm_pass1(puttvar(R,R1),_,4).
  101. $asm_pass1(putcon(C,R),Csym,6) :-
  102.      $member1((C,0,_),Csym).
  103. $asm_pass1(putnumcon(N,R),_,6).
  104. $asm_pass1(putfloatcon(I,R),_,6).
  105. $asm_pass1(putnil(R),_,2).
  106. $asm_pass1(putstr((S,N),R),Csym,6) :-
  107.      $member1((S,N,_),Csym).
  108. $asm_pass1(putstrv((S,N),V),Csym,6) :-
  109.      $member1((S,N,_),Csym).
  110. $asm_pass1(getstrv((S,N),V),Csym,6) :-
  111.      $member1((S,N,_),Csym).
  112. $asm_pass1(putlist(R),_,2).
  113. $asm_pass1(bldpvar(V),_,2).
  114. $asm_pass1(bldpval(V),_,2).
  115. $asm_pass1(bldtvar(R),_,2).
  116. $asm_pass1(bldtval(R),_,2).
  117. $asm_pass1(bldcon(C),Csym,6) :-
  118.      $member1((C,0,_),Csym).
  119. $asm_pass1(bldnumcon(N),_,6).
  120. $asm_pass1(bldfloatcon(N),_,6).
  121. $asm_pass1(bldnil,_,2).
  122. $asm_pass1(trymeelse(L,A),_,6).
  123. $asm_pass1(retrymeelse(L,A),_,6).
  124. $asm_pass1(trustmeelsefail(A),_,2).
  125. $asm_pass1(try(L,A),_,6).
  126. $asm_pass1(retry(L,A),_,6).
  127. $asm_pass1(trust(L,A),_,6).
  128. $asm_pass1(getpbreg(V),_,2).
  129. $asm_pass1(gettbreg(R),_,2).
  130. $asm_pass1(putpbreg(V),_,2).
  131. $asm_pass1(puttbreg(R),_,2).
  132. $asm_pass1(switchonterm(R,L,L1),_,10).
  133. $asm_pass1(switchonlist(R,L,L1),_,10).
  134. $asm_pass1(switchonbound(R, L1, L2), _,10).
  135. $asm_pass1(arg(I,T,X),_,4).
  136. $asm_pass1(arg0(I,T,X),_,4).
  137. $asm_pass1(get_tag(R1,R2), _,4).
  138. $asm_pass1(addreg(R,R1),_,4).
  139. $asm_pass1(subreg(R,R1),_,4).
  140. $asm_pass1(mulreg(R,R1),_,4).
  141. $asm_pass1(divreg(R,R1),_,4).
  142. $asm_pass1(idivreg(R,R1),_,4).
  143. $asm_pass1(and(R,R1),_,4).
  144. $asm_pass1(or(R,R1),_,4).
  145. $asm_pass1(lshiftl(R,R1),_,4).
  146. $asm_pass1(lshiftr(R,R1),_,4).
  147. $asm_pass1(negate(R),_,2).
  148. $asm_pass1(movreg(R,R1),_,4).
  149. $asm_pass1(putdval(V,R),_,4).
  150. $asm_pass1(putuval(V,R),_,4).
  151. $asm_pass1(call((P,N),B),Csym,6) :-
  152.      N >= 0 -> $member1((P,N,_),Csym) ; true.
  153. $asm_pass1(calld((P,N),B),Csym,6) :-
  154.      N >= 0 -> $member1((P,N,_),Csym) ; true.
  155. $asm_pass1(allocate,_,2).
  156. $asm_pass1(deallocate,_,2).
  157. $asm_pass1(proceed,_,2).
  158. $asm_pass1(execute((P,N)),Csym,6) :- 
  159.      $member1((P,N,_),Csym).
  160. $asm_pass1(callv(B),_,2).
  161. $asm_pass1(executev,_,2).
  162. $asm_pass1(jump(L),_,6).
  163. $asm_pass1(jumpz(L,R),_,6).
  164. $asm_pass1(jumpnz(L,R),_,6).
  165. $asm_pass1(jumplt(L,R),_,6).
  166. $asm_pass1(jumple(L,R),_,6).
  167. $asm_pass1(jumpgt(L,R),_,6).
  168. $asm_pass1(jumpge(L,R),_,6).
  169. $asm_pass1(fail,_,2).
  170. $asm_pass1(noop,_,2).
  171. $asm_pass1(halt,_,2).
  172. $asm_pass1(builtin(W),_,2).
  173. $asm_pass1(Junk,_,0) :-
  174.      $umsg(['*** Error in assembly: unknown opcode: ',Junk]).
  175.  
  176. /*    Fill in the values of any symbols which have not been defined
  177. with the value -2. */
  178.  
  179. $asmpass1_setundef([], N, N) :- !.
  180. $asmpass1_setundef([ (Pred, Arity, Val) | Rest ], Nout, Nin) :-
  181.     $conlength(Pred, L), 
  182.     Nmed is Nin + L + 6,
  183.     (var(Val) -> Val = -2 ; true),
  184.     $asmpass1_setundef(Rest, Nout, Nmed).
  185.  
  186. /*    Fill in the values of any predicates which are referenced and 
  187. defined within this module.  Append the names of any predicates which
  188. are defined but not referenced by this module.  Ignore predicates with
  189. arity < 0, these are strictly internal jumps that should not go via the
  190. symbol table.                                */
  191.  
  192. $asmpass1_fillin([], _).
  193. $asmpass1_fillin([ (Name, Arity, LcValue) | Rest ], Table) :-
  194.     $member1((Name, Arity, LcValue), Table),
  195.     $asmpass1_fillin(Rest, Table).
  196.  
  197. /*    Uniq creates a list (Ulist) containing only the first label
  198. encountered for each predicate-name arity pair and excludes all labels
  199. whose predicate-name arity pair have an arity of -1.  Labels with an
  200. arity of -1 are used as the targets of jump instructions only.    */
  201.  
  202. $asm_uniq([],_).
  203. $asm_uniq([ ((Pname, Arity,_),_) | Tail], Ulist) :-
  204.     (Arity = -1 ;                /* internal branch */
  205.      $member2((Pname, Arity, _), Ulist)),   /* already present in ST */
  206.     $asm_uniq(Tail, Ulist).
  207. $asm_uniq([ ((Pname,Arity,_),Lc) | Tail], Ulist) :-
  208.     $member1((Pname, Arity, Lc), Ulist),
  209.     $asm_uniq(Tail, Ulist).
  210.  
  211.  
  212. /* end asmpass11.P *********************************************/
  213.